package com.xnyzc.lhy.order.controller.approval;

import com.xnyzc.lhy.common.entity.Rv;
import com.xnyzc.lhy.common.exception.PangException;
import com.xnyzc.lhy.common.penum.EErrorCode;
import com.xnyzc.lhy.common.util.CheckUtil;
import com.xnyzc.lhy.common.util.TokenUtil;
import com.xnyzc.lhy.order.service.approval.IOaApprovalListService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Description 审批列表
 * @Author zhuyubin
 * @Date 2019/8/13 20:37
 **/
@RestController
@RequestMapping(value = "capi/approvalList")
public class OaApprovalListController {

    @Autowired
    private IOaApprovalListService iOaApprovalListService;

    /**
     * 审批列表
     * @param type 类型
     * @param current 当前页
     * @return
     */
    @GetMapping(value = "selectApprovalPage")
    public Rv selectApprovalPage(Integer type, Long current){
        Long userId = TokenUtil.getTokenUserId();
        if (CheckUtil.objIsEmpty(userId)){
            throw PangException.create(EErrorCode.tokenExpire);
        }
        String tag = TokenUtil.getTag();
        if (CheckUtil.objIsEmpty(tag)){
            throw PangException.create(EErrorCode.missingAuthArgs);
        }
        if (CheckUtil.objIsEmpty(type) || CheckUtil.objIsEmpty(current)){
            throw PangException.create(EErrorCode.missingArg);
        }
        return Rv.wrap(iOaApprovalListService.selectApprovalPage(userId, tag, type, current));
    }

    /**
     * 审批详情
     * @param orderNo 审批订单号
     * @return
     */
    @GetMapping(value = "getApproval")
    public Rv getApproval(String orderNo){
        Long userId = TokenUtil.getTokenUserId();
        if (CheckUtil.objIsEmpty(userId)){
            throw PangException.create(EErrorCode.tokenExpire);
        }
        String tag = TokenUtil.getTag();
        if (CheckUtil.objIsEmpty(tag)){
            throw PangException.create(EErrorCode.missingAuthArgs);
        }
        if (CheckUtil.objIsEmpty(orderNo)){
            throw PangException.create(EErrorCode.missingArg);
        }
        return Rv.wrap(iOaApprovalListService.getApproval(userId, tag, orderNo));
    }
}
